/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminFrame.java
 *
 * Created on 2009-11-30, 11:09:33
 */

package View;

import Control.CustomerServiceI;
import Model.CustomerI;
import java.util.ArrayList;
import javax.swing.JOptionPane;


/**
 *
 * @author Administrator
 */
public class AdminFrame extends javax.swing.JFrame {
private  CustomerServiceI csi=null;
private ArrayList list=null;
private String user;
    /** Creates new form AdminFrame */
    public AdminFrame() {
        super("Admin");
        initComponents();
        csi = new CustomerServiceI();
        initManagerJCombox();
    }

      public AdminFrame(String user ) {
        super("Admin");
        initComponents();
        name_jlb.setText("Welcome,    " + user + "!");
        csi = new CustomerServiceI();
        initManagerJCombox();
        this.user=user;
    }

    public void  initManagerJCombox(){
        manager_jcb.removeAll();
        list = (ArrayList)csi.findAll();
        if(list!=null){
            for(int i=0;i<list.size();i++){
                if(((CustomerI)list.get(i)).getPeople().equalsIgnoreCase("manager")){
                    manager_jcb.addItem(((CustomerI)list.get(i)).getUser());
                }
            }
          
        }
        else{
              JOptionPane.showMessageDialog(null,"Without Human Being");
              return;
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        back_jbt = new javax.swing.JButton();
        logout_jbt = new javax.swing.JButton();
        manager_jlb = new javax.swing.JLabel();
        manager_jcb = new javax.swing.JComboBox();
        manager_delete_jbt = new javax.swing.JButton();
        information_jlb = new javax.swing.JLabel();
        name_jlb = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        back_jbt.setBackground(new java.awt.Color(51, 51, 51));
        back_jbt.setForeground(new java.awt.Color(255, 255, 25));
        back_jbt.setText("Back");
        back_jbt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                back_jbtActionPerformed(evt);
            }
        });

        logout_jbt.setBackground(new java.awt.Color(51, 51, 51));
        logout_jbt.setForeground(new java.awt.Color(255, 255, 25));
        logout_jbt.setText("Logout");
        logout_jbt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logout_jbtActionPerformed(evt);
            }
        });

        manager_jlb.setText("Managers:");

        manager_jcb.setBackground(new java.awt.Color(102, 102, 0));
        manager_jcb.setEditable(true);
        manager_jcb.setForeground(new java.awt.Color(153, 153, 153));
        manager_jcb.setModel(new javax.swing.DefaultComboBoxModel(new String[] {""}));
        manager_jcb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manager_jcbActionPerformed(evt);
            }
        });

        manager_delete_jbt.setBackground(new java.awt.Color(51, 51, 51));
        manager_delete_jbt.setForeground(new java.awt.Color(255, 255, 25));
        manager_delete_jbt.setText("Delete");
        manager_delete_jbt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manager_delete_jbtActionPerformed(evt);
            }
        });

        information_jlb.setText("You can look over all of managers in here, and manager them:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(manager_jlb, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(manager_jcb, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addComponent(manager_delete_jbt)
                .addGap(158, 158, 158))
            .addGroup(layout.createSequentialGroup()
                .addComponent(back_jbt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(name_jlb, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                .addComponent(logout_jbt))
            .addGroup(layout.createSequentialGroup()
                .addComponent(information_jlb, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(87, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(back_jbt)
                    .addComponent(logout_jbt)
                    .addComponent(name_jlb, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addComponent(information_jlb)
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(manager_jlb)
                    .addComponent(manager_jcb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(manager_delete_jbt))
                .addGap(251, 251, 251))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void back_jbtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_back_jbtActionPerformed
                SuccessFrame su=new SuccessFrame(user);
                su.setVisible(true);
                this.dispose();
    }//GEN-LAST:event_back_jbtActionPerformed

    private void logout_jbtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logout_jbtActionPerformed
                LoginFrame login=new LoginFrame();
                login.setVisible(true);
                this.dispose();
    }//GEN-LAST:event_logout_jbtActionPerformed

    private void manager_delete_jbtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manager_delete_jbtActionPerformed
        // TODO add your handling code here:
        CustomerI ci = new CustomerI();
        ci.setUser(manager_jcb.getSelectedItem().toString());
        csi.deleteCustomer(ci);
        initManagerJCombox();
    }//GEN-LAST:event_manager_delete_jbtActionPerformed

    private void manager_jcbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manager_jcbActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_manager_jcbActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AdminFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton back_jbt;
    private javax.swing.JLabel information_jlb;
    private javax.swing.JButton logout_jbt;
    private javax.swing.JButton manager_delete_jbt;
    private javax.swing.JComboBox manager_jcb;
    private javax.swing.JLabel manager_jlb;
    private javax.swing.JLabel name_jlb;
    // End of variables declaration//GEN-END:variables

}
